<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/themes/icon.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript">
	$(function(){
		//默认对话框是关闭的
		$('#updataGds').dialog('close');
		$('#adddataGds').dialog('close');
		<!--配置表格-->
		$('#goods').datagrid({    
		    url:'${pageContext.request.contextPath}/findgoods',    
		    columns:[[
				{field:'checked',checkbox:true,width:100},
		        {field:'gid',title:'编号',width:100},    
		        {field:'gname',title:'商品名',width:100},    
		        {field:'ginventory',title:'库存量',width:100},
		        {field:'gprice',title:'商品价格',width:100},
		        {field:'gdate',title:'生产日期',width:100},
		        {field:'gquality',title:'保质期',width:100},
		        {field:'gaddress',title:'产地',width:100},
		        {field:'gcost',title:'进价',width:100},
		        {field:'gclassify',title:'商品类别',width:100,algin:'right'},
		    ]],
			pagination : true,
			toolbar : [ {
				iconCls : 'icon-add',
				text : '新增',
				handler : function() {
					$('#adddataGds').dialog('open');
				}
			}, '-', {
				iconCls : 'icon-remove',
				text : '删除',
				handler : function() {
					var gids='';
					var goods = $("#goods").datagrid('getSelections');
					$.messager.confirm('提示', '确认删除？', function(r) {
						$.each(goods,function(n,v){
							gids=gids+v.gid+','
					});
					$.ajax({
						type:'post',
						url:'${pageContext.request.contextPath}/deletegoods',
						data:{'gids':gids},
						dataType:"text",
						success:function(data){
						   if(data=="true"){
							   $("#goods").datagrid('reload'); 
						   }
						}
					})
				})
				}
			}, '-', {
				iconCls : 'icon-edit',
				text : '修改',
				handler : function() {
					var gds = $("#goods").datagrid('getSelections');
					if (gds.length != 1) {
						$.messager.confirm('提示', '请选择一条数据', function(r) {
							if (r) {
								$("#goods").datagrid('unselectAll');
							}
						})
					} else {
						$('#updataGds').dialog('open');
						var goods = gds[0];
						 $('#updataGds').form('load',goods);
					}
				}
			} ],
			striped : true,
			rownumbers : true,
		});
		<!--配置搜索框-->
		$('#searchGds').searchbox({
			searcher : function(value, name) {
				var gname = value;
				$('#goods').datagrid('reload', {
					searchname : gname,
				});
			}
		});
		<!--配置修改框-->
		$("#upGds").form({
			url:'${pageContext.request.contextPath}/updategoods',
			success:function(data){
				 if(data=="true"){
					$('#updataGds').dialog('close');
					$("#upGds").form('clear');
					$.messager.alert('我的消息','更新成功','info',function(){
						$('#goods').datagrid('reload');
					});
				 }else{
					 
				 }
			}
		});
		<!--配置增加框-->
		$("#addGds").form({
			url:'${pageContext.request.contextPath}/insertgoods',
			success:function(data){
				if(data=="true"){
					$('#adddataGds').dialog('close');
					$('#addGds').form('clear');
					$.messager.alert('我的消息','添加商品信息成功','info',function(){
						$('#goods').datagrid('reload');
					});
				}else{
					$.messager.alert('我的消息','添加商品信息失败，重新添加','info',function(){
						$("#addGds").form('clear');
					});
				}
			}
		});
		$("#ginventory").blur(function(){
			var str = $("#ginventory").val();
			if(!(/^[0-9]*$/.test(str))||str.length==0){
				$("#ginventory1").show();
				$("#ta").linkbutton({disabled:true});
			}else{
				$("#ginventory1").hide();
				$("#ta").linkbutton({disabled:false});
			}
		});
		$("#gprice").blur(function(){
			var str = $("#gprice").val();
			if(!(/^(([1-9]\d*)|0)(\.\d{1,2})?$/.test(str))||str.length==0){
				$("#gprice1").show();
				$("#ta").linkbutton({disabled:true});
			}else{
				$("#gprice1").hide();
				$("#ta").linkbutton({disabled:false});	
			}
		});
		$("#price").blur(function(){
			var str = $("#price").val();
			if(!(/^(([1-9]\d*)|0)(\.\d{1,2})?$/.test(str))||str.length==0){
				$("#price1").show();
				$("#tt").linkbutton({disabled:true});
			}else{
				$("#price1").hide();
				$("#tt").linkbutton({disabled:false});	
			}
		});
		$("#gquality").blur(function(){
			var str = $("#gquality").val();
			if(!(/^[1-9]\d*|0$/.test(str))||str.length==0){
				$("#gquality1").show();
				$("#ta").linkbutton({disabled:true});
			}else{
				$("#gquality1").hide();
				$("#ta").linkbutton({disabled:false});
			}
		});
		$("#gcost").blur(function(){
			var str = $("#gcost").val();
			if(!(/^(([1-9]\d*)|0)(\.\d{1,2})?$/.test(str))||str.length==0){
				$("#gcost1").show();
				$("#ta").linkbutton({disabled:true});
			}else{
				$("#gcost1").hide();
				$("#ta").linkbutton({disabled:false});
			}
		});
		
	});
	<!--配置事件-->
	function updataForm() {
			$("#upGds").form('submit');
	}
	function addForm() {
		$("#addGds").form('submit');
	}
		<!--配置日历-->
	 function myformatter(date){
         var y = date.getFullYear();
         var m = date.getMonth()+1;
         var d = date.getDate();
         return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
     }
     function myparser(s){
         if (!s) return new Date();
         var ss = (s.split('-'));
         var y = parseInt(ss[0],10);
         var m = parseInt(ss[1],10);
         var d = parseInt(ss[2],10);
         if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
             return new Date(y,m-1,d);
         } else {
             return new Date();
         }
     }
</script>
<body>
	<input id="searchGds" class="easyui-searchbox"
		data-options="prompt:'输入商品查询信息',width:150">
	<table id="goods"></table> 
	<!-- 配置修改框 -->
	<div id="updataGds" class="easyui-dialog" title="更新商品信息信息"
		style="width: 400px; height: 450px;" data-options="modal:true">
		<form id="upGds" method="post">
			<div style="margin-bottom: 20px;display: none;">
				<span>商品id</span>
				<input class="easyui-textbox" name="gid" style="width: 200px;" data-options="required:true">
			</div>
			<div style="margin-bottom: 20px">
				<span>&nbsp;&nbsp;&nbsp;&nbsp;商品名</span>
				<input class="easyui-textbox" name="gname" style="width: 200px"
					data-options="required:true" readonly="readonly" >
			</div>
			<div style="margin-bottom: 20px">
				<span>&nbsp;&nbsp;&nbsp;&nbsp;库存量</span>
				<input class="easyui-textbox" name="ginventory" style="width: 200px"
					data-options="required:true" readonly="readonly">
			</div>
			<div style="margin-bottom: 20px">
				<span>商品价格</span>
				<input  name="gprice"	style="width: 200px " class= "easyui-validatebox"
					data-options="required:true" id="price"><span style="display:none;color: red" id="price1">对不起，清输入有效的价格!</span>
			</div>
			<div style="margin-bottom: 20px">
				<span>生产日期</span>
				<input class="easyui-textbox" name="gdate"
					style="width: 200px" 
					data-options="required:true" readonly="readonly">
			</div>
			<div style="margin-bottom: 20px">
				<span>&nbsp;&nbsp;&nbsp;保质期</span>
				<input class="easyui-textbox" name="gquality"
					style="width: 200px" 
					data-options="required:true" readonly="readonly">
			</div>
			<div style="margin-bottom: 20px">
				<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;产地</span>
				<input class="easyui-textbox" name="gaddress"
					style="width: 200px"
					data-options="required:true" readonly="readonly">
			</div>
			<div style="margin-bottom: 20px">
				<span>商品类别</span>
				<input class="easyui-textbox" name="gclassify"
					style="width: 200px"
					data-options="required:true" readonly="readonly">
			</div>
		</form>
		<div style="text-align: center; padding: 5px 0;">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				onclick="updataForm()" style="width: 80px" id="tt">提交</a> 
		</div>
	</div>
	<!-- 配置商品增加框 -->
	<div id="adddataGds" class="easyui-dialog" title="增加商品"
		style="width: 400px; height: 450px;" data-options="modal:true">
		<form id="addGds" method="post">
		<div style="margin-bottom: 20px">
				<span>&nbsp;&nbsp;&nbsp;&nbsp;商品名</span>
				<input class="easyui-textbox" name="gname" style="width: 200px"
					data-options="required:true">
			</div>
			<div style="margin-bottom: 20px">
				<span>&nbsp;&nbsp;&nbsp;&nbsp;库存量</span>
				<input  name="ginventory" style="width: 200px" class="easyui-validatebox"
					data-options="required:true" id="ginventory"  ><span style="display:none;color: red" id="ginventory1">对不起，请输入有效的库存量!</span>
			</div>
			<div style="margin-bottom: 20px">
				<span>商品价格</span>
				<input  name="gprice"
					style="width: 200px" class="easyui-validatebox"
					data-options="required:true"  id="gprice" ><span style="display:none;color: red" id="gprice1">对不起，请输入有效的商品价格!</span>
			</div>
			<div style="margin-bottom: 20px">
				<span>生产日期</span>
				 <input editable=false class="easyui-datebox" labelPosition="top" data-options="formatter:myformatter,parser:myparser,required:true" style="width:200px;" name="gdate">
			</div>
			<div style="margin-bottom: 20px">
				<span>&nbsp;&nbsp;&nbsp;保质期</span>
				<input  name="gquality"
					style="width: 200px" class="easyui-validatebox"
					data-options="required:true" id="gquality"><span style="display:none;color: red" id="gquality1">对不起，请输入有效的保质期!</span>
			</div>
			<div style="margin-bottom: 20px">
				<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;产地</span>
				<input class="easyui-validatebox" name="gaddress"
					style="width: 200px"
					data-options="required:true" id="gaddress"><span style="display:none;color: red" id="gaddress1">对不起，请输入有效的产地!</span>
			</div>
			<div style="margin-bottom: 20px">
				<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;进价</span>
				<input name="gcost" class="easyui-validatebox"
					style="width: 200px"
					data-options="required:true" id="gcost" ><span style="display:none;color: red" id="gcost1">对不起，请输入有效的进价!</span>
			</div>
			<div style="margin-bottom: 20px">
				<span>商品类别</span>
				<select id="cc" class="easyui-combobox" name="gclassify"
					style="width: 200px;" editable=false data-options="required:true">
					<option value="1">饮料</option>
					<option value="2">生活用品</option>
					<option value="3">文具</option>
					<option  value="4">家用电器</option>
					<option value="5">餐饮</option>
					<option value="6">调料</option>
					<option value="7">食品</option>
				<select>
			</div>
			<div style="margin-bottom: 20px">
				<span>&nbsp;&nbsp;&nbsp;供应商</span> <select id="cc" class="easyui-combobox" name="sid"
					style="width: 200px;" editable=false data-options="required:true">
					<option value="1">深圳华尔</option>
					<option value="2">三星电子</option>
					<option value="3">宝洁</option>
					<option  value="4">飞利浦</option>
					<option value="5">伊利</option>
					<option value="6">美的</option>
					<option value="7">康师傅</option>
				<select>
			</div>
		</form>
		<div style="text-align: center; padding: 5px 0">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				onclick="addForm()" style="width: 80px" id="ta">提交</a> 
		</div>
		</div>
		
</body>
</html>